package com.anuai.abctest5.Controller;

import com.anuai.abctest5.Feign.AbcTest1TestFeign;
import com.anuai.abctest5.Feign.AbcTest2TestFeign;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/test5")
public class TestController {
    @RequestMapping("/hi")
    public String hi() {
        return "hi ,i'm ABCloud(test4)";
    }

    @RequestMapping("/hello")
    public String hello() {
        return "hello ,i'm ABCloud(test4)";
    }

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    AbcTest1TestFeign abcTest1TestFeign;

    @Autowired
    AbcTest2TestFeign abcTest2TestFeign;

    @RequestMapping("/restTemplate")
    @HystrixCommand(fallbackMethod = "restTemplateError")
    public String restTemplate() {
        String rtResult = restTemplate.getForObject("http://abc-test1/test1/hi", String.class);
        return rtResult;
    }

    @RequestMapping("/feign")
    public String feign() {
        return abcTest1TestFeign.nameFromAbcCfg();
    }

    @RequestMapping("/feign_test2")
    public String feign_test2() {
        return abcTest2TestFeign.nameFromAbcCfg();
    }

    public String restTemplateError() {
        return "Sorry,RestTemplate Error!";
    }
}
